import 'package:bilibili_getx_project/core/shared_preference/bilibili_shared_preference.dart';
import 'package:bilibili_getx_project/ui/pages/publish/publish_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import '../../../core/shared_preference/shared_preference_util.dart';
import 'main_state.dart';

class MainLogic extends GetxController {
  final MainState state = MainState();

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }

  ///更新App
  updateApp() {
    SmartDialog.show(
      builder: (ctx) {
        return Container(
          width: 230.r,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text("升级提醒"),
              Text("版本7.13.0\n更新包体积：107MB"),
              Container(
                child: Text("立即更新"),
              ),
              Container(
                child: Text("以后再说"),
              )
            ],
          ),
        );
      },
      clickMaskDismiss: false,
    );
  }

  exchangeLanguage() {
    String? locale =
        SharedPreferenceUtil.getString(BilibiliSharedPreference.locale);
    if (locale == "en") {
      SharedPreferenceUtil.setString(BilibiliSharedPreference.locale, 'zh');
      Get.updateLocale(const Locale('zh', 'CN'));
    } else {
      SharedPreferenceUtil.setString(BilibiliSharedPreference.locale, 'en');
      Get.updateLocale(const Locale('en', 'US'));
    }
  }

  exchangeBottomNavigationBar(i) {
    if (i == 2) {
      Get.toNamed(PublishView.routeName);
    } else {
      state.currentIndex = i;
      update();
    }
  }
}
